<?php
require(__META_CONTROLS_GEN__ . '/SchoolUsedTitlesMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * SchoolUsedTitles class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single SchoolUsedTitles object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a SchoolUsedTitlesMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class SchoolUsedTitlesMetaControl extends SchoolUsedTitlesMetaControlGen {
    // Initialize fields with default values from database definition
    /*
		public function __construct($objParentObject, SchoolUsedTitles $objSchoolUsedTitles) {
			parent::__construct($objParentObject,$objSchoolUsedTitles);
			if ( !$this->blnEditMode ){
				$this->objSchoolUsedTitles->Initialize();
			}
		}
    */
    private $txtACompetitor;

    private $dttTime;

    public function lstUsedSince_Create($strControlId = null) {
        $this->lstUsedSince = new QListBox($this->objParentObject, $strControlId);
        $this->lstUsedSince->Name = QApplication::Translate('Used Since');
        $this->lstUsedSince->AddItem(QApplication::Translate('- UnKnown -'), null);
        $objUsedSinceArray = Season::LoadAll();
        if ($objUsedSinceArray) foreach ($objUsedSinceArray as $objUsedSince) {
                $objListItem = new QListItem($objUsedSince->__toString(), $objUsedSince->Id);
                if (($this->objSchoolUsedTitles->UsedSince) && ($this->objSchoolUsedTitles->UsedSince->Id == $objUsedSince->Id))
                    $objListItem->Selected = true;
                $this->lstUsedSince->AddItem($objListItem);
            }
        return $this->lstUsedSince;
    }


    public function lstSeries_Create($strControlId = null) {
        $this->lstSeries = new QAjaxAutoCompleteTextBox($this->objParentObject, 'AutoListSeries_Change',$strControlId);
        $this->lstSeries->Name = QApplication::Translate('Series');
        $this->lstSeries->MustMatch=true;
        //if (($this->objSchoolUsedTitles->Series) && ($this->objSchoolUsedTitles->Series->Id == $objSeries->Id))
        $this->lstSeries->MaxLength = Org::NameMaxLength;
        return $this->lstSeries;

    }
    public function SaveSchoolUsedTitles() {
        try {
                        //Prepare data for Record Info
            $this->dttTime = new QDateTime();
            $this->dttTime->setDate (date("Y"), date("m"), date("d"));
            $this->dttTime->setTime (date("H"), date("i"), date("s"));
            //Get Current user
            $CurrentUser = $_SESSION['User']['Id'];

            $EUser = $_SESSION['User']['Id'];

            // Update any fields for controls that have been created
            //if ($this->txtId) $this->objSchoolUsedTitles->Id = $this->txtId->Text
            $this->objSchoolUsedTitles->OrgId= $_SESSION["Org"]->Id;
            if ($this->lstStage) $this->objSchoolUsedTitles->StageId = $this->lstStage->SelectedValue;
            if ($this->lstSeries) $this->objSchoolUsedTitles->SeriesId = $this->lstSeries->SelectedValue();
            if ($this->lstUsedSince) $this->objSchoolUsedTitles->UsedSinceId = $this->lstUsedSince->SelectedValue;
            if ($this->txtNote) $this->objSchoolUsedTitles->Note = $this->txtNote->Text;


            if ($this->blnEditMode) {
                //*** Update
                $this->objSchoolUsedTitles->UpdateBy   = $CurrentUser;
                $this->objSchoolUsedTitles->UpdateDate = $this->dttTime;
            }
            else {
                //**** New
                $this->objSchoolUsedTitles->Euser =  $EUser;
                //$this->objSchoolUsedTitles->SchoolId = $_SESSION['OrgId'];
                $this->objSchoolUsedTitles->CreateBy   = $CurrentUser;
                $this->objSchoolUsedTitles->CreateDate = $this->dttTime;
            }

            $this->objSchoolUsedTitles->Save();
            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }

}
?>